import request from "@/utils/request";
import { AxiosPromise } from "axios";
import {
  ModelApp,
  ModelId,
  ModelapiKey,
  ModelCategory,
  ModelList,
  ModelInfo,
  ModelBatch,
  ModelStatus,
  ModelVipPrice,
} from "./types";

// 分销商管理 - 获取指定分销商已绑定的小程序列表
export function getBindedAppslist(data: ModelId): AxiosPromise<Array<any>> {
  return request({
    url: `/api/operation/Tenant/apps`,
    method: "get",
    params: data,
  });
}

// 分销商管理 - 给指定分销商 绑定单个小程序
export function bindApp(data: ModelApp) {
  return request({
    url: "/api/operation/Tenant/apps",
    method: "post",
    params: data,
  });
}

// 分销商管理 - 指定分销商 解除绑定小程序
export function deleteBindApp(data: ModelApp) {
  return request({
    url: `/api/operation/Tenant/apps`,
    method: "delete",
    params: data,
  });
}

// 分销商管理 - 给指定分销商 绑定小程序
export function setbindApps(data: ModelId) {
  return request({
    url: `/api/operation/Tenant/apps?tenantId=${data.tenantId}`,
    method: "put",
    data: data.ids,
  });
}

// 分销商管理 - 获取指定分销商apikey
export function getApiKey(data: number): AxiosPromise<any> {
  return request({
    url: `/api/operation/Tenant/open-api-key?tenantId=${data}`,
    method: "get",
  });
}

// 分销商管理 - 获取指定分销商apikey
export function setApiKey(data: ModelapiKey) {
  return request({
    url: `/api/operation/Tenant/open-api-key?tenantId=${data.tenantId}`,
    method: "put",
    data: data.params,
  });
}

// 分销商管理 - 获取随机生成的apiKey
export function generate(): AxiosPromise<Record<string, any>> {
  return request({
    url: `/api/operation/Tenant/open-api-key/generate`,
    method: "get",
  });
}

// 分销商管理 - 分销商列表查询
export function searchTenant(
  data: ModelList
): AxiosPromise<Record<string, any>> {
  return request({
    url: `/api/operation/Tenant/search`,
    method: "post",
    data,
  });
}

// 分销商管理 - 新增分销商
export function addTenant(data: ModelInfo): AxiosPromise<Record<string, any>> {
  return request({
    url: `/api/operation/Tenant`,
    method: "post",
    data,
  });
}

// 分销商管理 - 修改分销商
export function updateTenant(
  data: ModelInfo
): AxiosPromise<Record<string, any>> {
  return request({
    url: `/api/operation/Tenant/${data.id}`,
    method: "put",
    data,
  });
}

// 分销商管理 - 批量修改分类
export function batchCategory(
  data: ModelBatch
): AxiosPromise<Record<string, any>> {
  return request({
    url: `/api/operation/Tenant/batch/modify/category`,
    method: "post",
    data,
  });
}

// 分销商管理 - 获取分类查询列表
export function categoryList(): AxiosPromise<Record<string, any>> {
  return request({
    url: `/api/operation/Tenant/category/list`,
    method: "get",
  });
}

// 分销商管理 - 新增分类查询
export function addCategory(data: string): AxiosPromise<Record<string, any>> {
  return request({
    url: `/api/operation/Tenant/category`,
    method: "post",
    data: { name: data },
  });
}

// 分销商管理 - 更新分类查询
export function updateCategory(
  data: ModelCategory
): AxiosPromise<Record<string, any>> {
  return request({
    url: `/api/operation/Tenant/category/${data.id}`,
    method: "put",
    data: { name: data.name },
  });
}
// 分销商管理 - 删除分类查询
export function deleteCategory(
  data: number
): AxiosPromise<Record<string, any>> {
  return request({
    url: `/api/operation/Tenant/category/${data}`,
    method: "delete",
  });
}

// 分销商管理 - 设置分销商启用状态
export function setEnabled(
  data: ModelStatus
): AxiosPromise<Record<string, any>> {
  return request({
    url: `/api/operation/Tenant/${data.id}/enabled`,
    method: "patch",
    params: { enabled: data.enabled },
  });
}

// 分销商管理列表 - 获取VIP价格档位
export function getDistributorVipPrice(data: String) {
  return request({
    url: `/api/operation/tenant/configs/${data}/vip-price-tiers`,
    method: "get",
  });
}

// 分销商管理列表 - 更新VIP价格档位
export function setDistributorVipPrice(data: ModelVipPrice) {
  return request({
    url: `/api/operation/tenant/configs/vip-price-tiers`,
    method: "put",
    data,
  });
}
